package com.system.HRDepartment.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.system.HRDepartment.dao.HRRepository;
import com.system.employee.entity.Employee;
import com.system.common.util.Sex;

@Service
@Transactional
public class HRService implements IHRService {
	@Autowired
	private HRRepository hrRepository;
	public void saveOrUpdate(Employee employee) {
		if(null!=employee.getEmpId()) {
		hrRepository.updateEmployee(employee.getEmpId(),employee.getEmpName(),employee.getSex(),employee.getBirthday(),employee.getBornPlace(),employee.getAddress(),employee.getEmail(),employee.getPhone(),employee.getEducation(),employee.getPolitical(),employee.getEthnic(),employee.getIdcard(),employee.getIdcardImg());
		}else {
		hrRepository.save(employee);
		}
	}
	public void delete(Employee employee) {
		hrRepository.delete(employee);
	}
	public Employee findOne(Long id) {
		return hrRepository.findByEmpId(id);
	}
	public List<Employee> findAll(){
		return (List<Employee>) hrRepository.findAll();
	}
	
	//自定义查询，传参

   	public int saveOrUpdate(Long id, String empName,Sex sex,Date birthday,String bornPlace,String address,String email,String phone,String education,String political,String ethnic,String idcard,String idcardImg) {
   		return hrRepository.updateEmployee(id, empName, sex, birthday, bornPlace, address, email, phone, education, political, ethnic, idcard, idcardImg);
   	}
	public int deleteEmployees(Long[] ids) {
		return hrRepository.deleteEmployees(ids);
	}
	
	//自定义分页查询
	public Page<Employee> findAll(String empName ,Pageable pageable){
		return hrRepository.findAll(empName, pageable);
	}
	
	
	
}
